import {CommonRouters, SystemRouters} from "@/router";

const system = {
    state: {
        sidebar: true,
        routers: null,
        addRouters: []
    },

    mutations: {
        TOGGLE_SIDEBAR: state => {
            state.sidebar = !state.sidebar
        },

        SET_ROUTERS: (state, routers) => {
            //业务路由
            state.addRouters = routers

            //将业务路由与公共路由合并
            state.routers = CommonRouters.concat(routers)
        }
    },

    actions: {
        //侧边栏Sidebar展开或折叠
        ToggleSideBar({commit, state}) {
            commit('TOGGLE_SIDEBAR')
        },

        //生成路由表
        GeneratorRouters({ commit }, data) {
            return new Promise((resolve, reject) => {
                commit('SET_ROUTERS', data)
                resolve()
            })
        },
    }
}

export default system
